#
# Testing
#

ENABLE_TESTING()

# Automatically create tests using files named "Test*.cpp"
FILE(GLOB TEST_PROGS "*Test*.cpp")
FOREACH(TEST_PROG ${TEST_PROGS})
    GET_FILENAME_COMPONENT(TEST_ROOT ${TEST_PROG} NAME_WE)
    IF ((${TEST_ROOT} MATCHES TestVectorizeAvx*) AND NOT X86)
        CONTINUE()
    ENDIF()
    ADD_EXECUTABLE(${TEST_ROOT} ${TEST_PROG})
    IF (OPENMM_BUILD_SHARED_LIB)
        TARGET_LINK_LIBRARIES(${TEST_ROOT} ${SHARED_TARGET})
    ELSE (OPENMM_BUILD_SHARED_LIB)
        TARGET_LINK_LIBRARIES(${TEST_ROOT} ${STATIC_TARGET})
    ENDIF (OPENMM_BUILD_SHARED_LIB)
    SET(EXTRA_TEST_FLAGS "${EXTRA_COMPILE_FLAGS}")
    IF((${TEST_ROOT} MATCHES TestVectorize) AND X86 AND NOT MSVC)
        SET(EXTRA_TEST_FLAGS "${EXTRA_COMPILE_FLAGS} -msse4.1")
    ENDIF()
    IF((${TEST_ROOT} MATCHES TestVectorizeAvx) AND X86 AND NOT MSVC)
        SET(EXTRA_TEST_FLAGS "${EXTRA_COMPILE_FLAGS} -mavx")
    ENDIF()
    IF((${TEST_ROOT} MATCHES TestVectorizeAvx2) AND X86 AND NOT MSVC)
        SET(EXTRA_TEST_FLAGS "${EXTRA_COMPILE_FLAGS} -mfma -mavx2")
    ENDIF()
    SET_TARGET_PROPERTIES(${TEST_ROOT} PROPERTIES LINK_FLAGS "${EXTRA_LINK_FLAGS}" COMPILE_FLAGS "${EXTRA_TEST_FLAGS}")
    ADD_TEST(${TEST_ROOT} ${EXECUTABLE_OUTPUT_PATH}/${TEST_ROOT})
ENDFOREACH(TEST_PROG ${TEST_PROGS})

